package cn.itcast.nems.common.captcha.web.o;

import cn.itcast.nems.common.captcha.SmsCaptchaService;
import cn.itcast.nems.common.captcha.vo.SmsCaptchaSendResultVo;
import cn.itcast.nems.common.captcha.vo.SmsCaptchaSendVo;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/o/captcha/sms")
@RequiredArgsConstructor
public class SmsCaptchaController {
	
    private final SmsCaptchaService smsCaptchaService;

    /**
     * 
     * 功能描述：发送一条短信验证码：六位数字
     *
     * @param mobile
     * @return
     * 
     * @author 刘曙
     *
     * @since 2024年4月14日
     *
     * @update:[变更日期YYYY-MM-DD][更改人姓名][变更描述]
     */
    @PostMapping
    public ResponseEntity<SmsCaptchaSendResultVo> send(@RequestBody SmsCaptchaSendVo sendVo) {
        return ResponseEntity.status(HttpStatus.CREATED)
                .body(new SmsCaptchaSendResultVo(smsCaptchaService.send(sendVo.getMobile(), "", "", sendVo.getTid())));
    }
    
    /**
     * 确认验证码是否正确
     * @param code 用户输入的验证码值
     * @param token 验证码token
     * @return
     */
//    @ApiOperation(value = "确认短信验证码是否正确", notes = "传入用户输入的验证码以及验证码对应的token确认是否正确")
//    @ApiResponses({@ApiResponse(code = 200, message = "验证码有效"), @ApiResponse(code = 404 , message = "验证码已过期或不正确！")})
//    @GetMapping("/captcha/sms")
//    @ApiImplicitParams({@ApiImplicitParam(name = "phone", value = "发送验证码的手机号" , dataType = "string", required = true, paramType = "query", example = "13888888888"),
//    	@ApiImplicitParam(name = "code", value = "学员在前端输入的验证码值" , dataType = "int", required = true, paramType = "query", example = "888888"),
//    	@ApiImplicitParam(name = "token", value = "验证码对应的token，关键信息所在" , dataType = "string", required = true, paramType = "query")})
//    public Result<String> verify(@RequestParam String phone, @RequestParam Integer code, @RequestParam String token) {
//    	boolean isValid = smsCaptchaService.verify(phone, code, token);
//		if (isValid ) {
//        	return result(String.valueOf(code));
//		} else {
//			return result( NOT_FOUND );
//		}
//    }
}
